﻿using EntityModel;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace API.Controllers
{  
    [Route("api/[controller]")]
    [ApiController]
    public class ActivitieController : ControllerBase
    {

       
            private readonly DZJDBcontext db;
            /// <summary>
            /// 数据库
            /// </summary>

            public ActivitieController(DZJDBcontext context)
            {
                db = context;
            }
            [HttpGet]
            public List<EM_Activitie> GetAll()
            {
            //select * from EM_Activitie 查找
            return db.EM_Activitie.ToList();
            }
            [HttpPost]
            public bool Add(EM_Activitie em_Activitie)
            {
                //sql insert into  set 活动人数增加
                db.EM_Activitie.Add(em_Activitie);

                int result = db.SaveChanges();
                return result > 0 ? true : false;
            }

            [HttpDelete]
            public bool Delete(Guid ID)
            {
            EM_Activitie? em_Activitie = new EM_Activitie();
            em_Activitie = db.EM_Activitie.Where(a => a.ID == ID).SingleOrDefault();

                int result = 0;
                if (em_Activitie != null)
                {
                    //sql update...
                    db.EM_Activitie.Remove(em_Activitie);
                    result = db.SaveChanges();
                }



                return result > 0 ? true : false;
            }
        }
    }



